package webStudio7i.servlet;

import java.io.IOException;
import java.util.Collection;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import webStudio7i.modelo.Usuario;
import webStudio7i.negocio.UsuarioBll;

/**
 * Servlet implementation class MostrarDatosClienteServlet
 */
public class MostrarDatosClienteServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public MostrarDatosClienteServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		
		String dato = request.getParameter("login");
		
		UsuarioBll usuBll = new UsuarioBll();
		System.out.println(dato);
		
		try {
		
			Usuario usuario = usuBll.consultarUsuario(dato);
			System.out.println(usuario.getApellido());
			
			request.setAttribute("usuario", usuario);
			RequestDispatcher rd = request.getRequestDispatcher("datosCliente.jsp");
			rd.forward(request, response);

		} catch (Exception e) {
			System.out.println(e.getMessage());
			RequestDispatcher rd = request.getRequestDispatcher("error.jsp");
			rd.forward(request, response);
		}
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	}

}
